//
//  welComeViewController.m
//  footBoll
//
//  Created by cckv on 2017/10/14.
//  Copyright © 2017年 cckv. All rights reserved.
//

#import "welComeViewController.h"

@interface welComeViewController ()

@end

@implementation welComeViewController
- (BOOL)shouldAutorotate

{
    
    return YES;
    
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations

{
    return UIInterfaceOrientationMaskPortrait;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self reachability];
    
}
- (void)reachability
{
    // 1.获得网络监控的管理者
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    // 2.设置网络状态改变后的处理
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        // 当网络状态改变了, 就会调用这个block
        switch (status) {
            case AFNetworkReachabilityStatusUnknown: // 未知网络
                NSLog(@"未知网络");
                break;
            case AFNetworkReachabilityStatusNotReachable: // 没有网络(断网)
                NSLog(@"没有网络(断网)");
            {
                UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"没有网络连接", nil) message:NSLocalizedString(@"请检查您的网络是否正常", nil) preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [self reachability];
                }];
                [alertVc addAction:action];
                [self presentViewController:alertVc animated:YES completion:nil];
                
            }
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN: // 手机自带网络
                NSLog(@"手机自带网络");
                
                [self getData];
                
                break;
            case AFNetworkReachabilityStatusReachableViaWiFi: // WIFI
                NSLog(@"WIFI");
                [self getData];
                
                break;
        }
    }];
    // 3.开始监控
    [mgr startMonitoring];
}

- (void)getData
{
    [SVProgressHUD showWithStatus:NSLocalizedString(@"加载中。。。", nil)];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    [manager POST:@"http://result.eolinker.com/I5AGQmkfac673092fbdcab2cd92efc19675f2750ed97ca1?uri=cckv.ball" parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [SVProgressHUD dismiss];
        
        if ([responseObject[@"show"] boolValue]) {
            
            webViewController *webVc = [[webViewController alloc] init];
            webVc.urlStr = responseObject[@"url"];
            [UIApplication sharedApplication].keyWindow.rootViewController = webVc;
        }else{
             [UIApplication sharedApplication].keyWindow.rootViewController = [[homeViewController alloc] init];
        }

        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"123");
         [SVProgressHUD dismiss];
        [UIApplication sharedApplication].keyWindow.rootViewController = [homeViewController new];
    }];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
